package com.xiaohudie.suanfa;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

/**
 * @Author xiao hu die
 * @Date 2022/1/20 21:04
 * @Version 1.0
 */
/**冒泡排序*/
public class BubbleSort {
    public static void main(String[] args) {
        /*int[] a ={25,26,2,4,5,1,36,2,3,21,0,2,4,5,5,555,2,6,6,2223};*/
        int a[] =new int[90000];
        for (int i=0;i<90000;i++){
            a[i]= (int) (Math.random()*80000);
        }
        Date data = new Date();
        SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(data);
        System.out.println(format);
        BubbleSort(a);
        Date data2 = new Date();
        String format2 = simpleDateFormat.format(data2);
        System.out.println(format2);
        /*String s = Arrays.toString(a);
        System.out.println(s);*/
    }
    /**冒泡排序方法*/
    public static void BubbleSort(int[] ints){
     /**定义一个boolean*/
     boolean b =false;
      for (int i=0;i<ints.length-1;i++){
         for (int j=0;j<ints.length-1-i;j++){
             if (ints[j]>ints[j+1]){
                 jiaoHuan(ints,j,j+1);
                b=true;
             }
         }
         if (!b){
             break;
         }else {
             b=false;
         }
      }
    }
    /**交换数组值的方法*/
    public  static  void jiaoHuan(int[] ints,int i,int j){
        int a =ints[i];
        ints[i] =ints[j];
        ints[j] =a;
    }
}
